from unittest import TestCase
from ddt import ddt, data, unpack
from selenium import webdriver
import Data
import Operation


@ddt
class Test_Login(TestCase):
    @data(*Data.LoginData.right)
    @unpack
    def test_right_login(self, name, pwd, expect):
        driver = webdriver.Chrome()
        driver.get("http://localhost:90")
        login = Operation.Login()
        login.right_login(name, pwd, driver)
        result = login.right_login_result(driver)
        if result != expect:
            driver.save_screenshot("name" + "pwd" + ".jpg")
        self.assertEqual(expect, result)

    @data(*Data.LoginData.wrongname)
    @unpack
    def test_wrong_name(self, name, pwd, expect):
        driver = webdriver.Chrome()
        driver.get("http://localhost:90")
        login = Operation.Login()
        login.wrong_name_login(name, pwd, driver)
        result = login.wrong_name_result(driver)
        if result != expect:
            driver.save_screenshot("name" + "pwd" + ".jpg")
        self.assertEqual(expect, result)

    @data(*Data.LoginData.wrongpwd)
    @unpack
    def test_wrong_pwd(self, name, pwd, expect):
        driver = webdriver.Chrome()
        driver.get("http://localhost:90")
        login = Operation.Login()
        login.right_login(name, pwd, driver)
        result = login.wrong_pwd_result(driver)
        if result != expect:
            driver.save_screenshot("name" + "pwd" + ".jpg")
        self.assertEqual(expect, result)
